export const setDocumentTitle = function (title) {
  document.title = title
  const ua = navigator.userAgent
  // eslint-disable-next-line
  const regex = /\bMicroMessenger\/([\d\.]+)/
  if (regex.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
    const i = document.createElement('iframe')
    i.src = ''
    i.style.display = 'none'
    i.onload = function () {
      setTimeout(function () {
        i.remove()
      }, 9)
    }
    document.body.appendChild(i)
  }
}

export const domTitle = ''
// 防抖
export function _debounce(fn, delay) {
  var delay = delay || 50;
  var timer;
  return function () {
    var th = this;
    var args = arguments;

    if (timer) {

      clearTimeout(timer);

    }

    timer = setTimeout(function () {

      timer = null;

      fn.apply(th, args);

    }, delay);

  };

}
export function fnThrottle(fn, delay, atleast) {
  let timer = null;
      let previous = null;
      return function(){
        let now = +new Date()
        if(!previous) previous = now;
        if(atleast && now - previous > atleast){
          fn();
          previous = now;
          clearTimeout(timer)
        }else{
          clearTimeout(timer)
          timer = setTimeout(()=>{
            fn();
            previous = null
          },delay)
        }
      }

}